home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2099 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: solon.com!not-for-mail
  2. From: seebs@solutions.solon.com (Peter Seebach)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: atol or strtol ?
  5. Date: 18 Jan 1996 21:28:57 -0600
  6. Organization: Usenet Fact Police (Undercover)
  7. Message-ID: <4dn35p$f28@solutions.solon.com>
  8. References: <4dbobq$763@jupiter.planet.net> <4dk4sc$dmj@spanky.pls.ov.com> <ALUN.CHAMPION.96Jan18103414@g7240065.bridge.bst.bls.com>
  9. NNTP-Posting-Host: solutions.solon.com
  10.  
  11. In article <ALUN.CHAMPION.96Jan18103414@g7240065.bridge.bst.bls.com>,
  12. Alun Champion <Alun.Champion@bridge.bst.bls.com> wrote:
  13. >    for (;;) {
  14. >        num = strtol(ptr, &p, 0);
  15. >        if (errno && errno != ERANGE) /* We can deal with ERANGE problems. */
  16.  
  17. Huh?
  18.  
  19. What gives you the idea this is correct?
  20.  
  21. It is unclear what the semantics are; ANSI asserts that a function may set
  22. errno whether or not there was an error, *if* the function does not define
  23. its usage of errno.  However, even if it does, since the standard has not
  24. seen fit to declare otherwise, we have no guarantee that errno was not
  25. set, either by strtol, or by some other previous call.
  26.  
  27. If you set errno to 0 before calling strtol, you are safer, but even then,
  28. I see no guarantee from the standard that errno cannot be set for reasons
  29. not mentioned.  (If anyone can verify this, or establish that the library
  30. may *not* set errno without an error, when it documents conditions for
  31. setting it, please let me know.)
  32.  
  33. It is almost never correct to check whether or not errno has been set.
  34. Your current implementation could fail capriciously because some earlier
  35. call set errno to a value other than ERANGE.
  36.  
  37. -s
  38. -- 
  39. Peter Seebach - seebs@solon.com - Copyright 1995 Peter Seebach.
  40. C/Unix proto-wizard -- C/Unix questions? Send mail for help.  No, really!
  41. Using trn?  Weird new newsgroup problem?  I know the fix!  Email me!
  42. The *other* C FAQ - ftp taniemarie.solon.com /pub/c/afq - Not A Flying Toy
  43.